﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using TRPOP.CRM.Component.Model;
using TRPOP.CRM.Component.DALSQLServer;
using TRPOP.Common;

namespace TRPOP.CRM.Component.Business
{
    /// <summary>
    /// 员工信息管理
    /// </summary>
    public class EmployeeManage
    {
        /// <summary>
        /// Employee 登录
        /// </summary>
        /// <param name="nvcEmployeeName"></param>
        /// <param name="nvcLoginPassword"></param>
        /// <returns></returns>
        public static EmployeeInfo CheckLogin(string nvcEmployeeName, string nvcLoginPassword)
        {
            string strUsername = nvcEmployeeName.Trim().SQLFilter();
            string strPWD = nvcLoginPassword.Trim().MD5Normal().SQLFilter();

            List<EmployeeInfo> oList = new EmployeeDAL().GetEmployeeInfosByNamePWD(strUsername, strPWD);

            if (oList != null && oList.Count >= 1)
            {
                return oList[0];
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获取ID为1的用户信息
        /// </summary>
        /// <returns></returns>
        public static EmployeeInfo GetAdminEmployeeInfo()
        {
            return new EmployeeDAL().GetInfoById(1);
        }

        /// <summary>
        /// 获取员工信息
        /// </summary>
        /// <returns></returns>
        public static EmployeeInfo GetEmployeeInfo(int intID)
        {
            return new EmployeeDAL().GetInfoById(intID);
        }

        /// <summary>
        /// 用户修改个人密码
        /// </summary>
        /// <param name="oEmployeeInfo"></param>
        /// <param name="strPassword"></param>
        /// <returns></returns>
        public static bool SavePasword(EmployeeInfo oEmployeeInfo, string strPassword)
        {
            oEmployeeInfo.nvcLoginPassword = strPassword.Trim().MD5Normal();

            return new EmployeeDAL().Save(oEmployeeInfo);
        }

        /// <summary>
        /// 删除员工信息
        /// </summary>
        /// <param name="intID"></param>
        /// <returns></returns>
        public static bool DeleteInfoById(int intID)
        {
            return new EmployeeDAL().DeleteInfoById(intID);
        }

        /// <summary>
        /// 删除多个员工信息
        /// </summary>
        /// <param name="strIDs"></param>
        /// <returns></returns>
        public static bool DeleteInfoByIds(string strIDs)
        {
            return new EmployeeDAL().DeleteInfoByIds(strIDs);
        }

        /// <summary>
        /// 获取 员工信息 为了列表显示
        /// </summary>
        /// <param name="intPageNumber"></param>
        /// <param name="intPageSize"></param>
        /// <param name="strCondition"></param>
        /// <param name="strOrderby"></param>
        /// <param name="intRecordCount"></param>
        /// <returns></returns>
        public static List<EmployeeSimpleInfo> GetEmployeeSimpleInfoPager(int intPageNumber, int intPageSize, string strCondition, string strOrderby, out int intRecordCount)
        {
            return new EmployeeDAL().GetEmployeeSimpleInfoPager(intPageNumber, intPageSize, strCondition, strOrderby, out  intRecordCount);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="intPageNumber"></param>
        /// <param name="intPageSize"></param>
        /// <param name="strOrderby"></param>
        /// <param name="intRecordCount"></param>
        /// <returns></returns>
        public static List<EmployeeSaleTotalInfo> GetEmployeeTitleInfoPager(int intPageNumber, int intPageSize, string strCondition, string strOrderby, out int intRecordCount)
        {
            return new EmployeeDAL().GetEmployeeTitleInfoPager(intPageNumber, intPageSize,strCondition, strOrderby, out  intRecordCount);
        }
        /// <summary>
        /// 检测 员工编号是否存在
        /// </summary>
        /// <param name="strEmployeeNumber"></param>
        /// <returns></returns>
        public static bool CheckEmployeeNumberExist(string strEmployeeNumber)
        {
            return new EmployeeDAL().CheckEmployeeNumberExist(strEmployeeNumber);
        }

        /// <summary>
        /// 检测 员工姓名是否存在
        /// </summary>
        /// <param name="strEmployeeNumber"></param>
        /// <returns></returns>
        public static bool CheckEmployeeNameExist(string strEmployeeNumber)
        {
            return new EmployeeDAL().CheckEmployeeNameExist(strEmployeeNumber);
        }

        /// <summary>
        /// 保存 员工信息
        /// </summary>
        /// <param name="oEmployeeInfo"></param>
        /// <returns></returns>
        public static bool SaveEmployeeInfo(EmployeeInfo oEmployeeInfo)
        {
            return new EmployeeDAL().Save(oEmployeeInfo);
        }

        /// <summary>
        /// 记录跟踪日志
        /// </summary>
        /// <param name="oWorkingLogInfo"></param>
        /// <returns></returns>
        public static bool SaveWorkLog(WorkingLogInfo oWorkingLogInfo)
        {
            return new WorkingLogDAL().Save(oWorkingLogInfo);
        }

        /// <summary>
        /// 获取跟踪信息
        /// </summary>
        /// <param name="intID"></param>
        /// <returns></returns>
        public static WorkingLogInfo GetWorkLog(int intID)
        {
            return new WorkingLogDAL().GetInfoById(intID);
        }

        /// <summary>
        /// 保存批注信息
        /// </summary>
        /// <param name="oWorkCommentInfo"></param>
        /// <returns></returns>
        public static bool SaveWorkComment(WorkCommentInfo oWorkCommentInfo)
        {
            return new WorkCommentDAL().Save(oWorkCommentInfo);
        }

        /// <summary>
        /// 获取批注信息
        /// </summary>
        /// <param name="intID"></param>
        /// <returns></returns>
        public static WorkCommentInfo GetWorkComment(int intID)
        {
            return new WorkCommentDAL().GetInfoById(intID);
        }
    }
}
